﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace IDE
{
    public partial class Consola : Form
    {
        private int lineaError;
        public int lineaMarcadaError
        {
            get
            {
                return this.lineaError;
            }
            set
            {
                this.lineaError = value;
            }
        }

        public Consola(Form parent)
        {
            InitializeComponent();
            this.MdiParent = parent;
        }

        public Consola()
        {
            InitializeComponent();
        }

        private void Consola_Load(object sender, EventArgs e)
        {
            Console.MouseDoubleClick += Console_MouseDoubleClick;
        }

        void Console_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            int firstcharindex = Console.GetFirstCharIndexOfCurrentLine();
            int currentline = Console.GetLineFromCharIndex(firstcharindex);
            //MessageBox.Show(firstcharindex + " " + currentline);
            //string currentlinetext = Console.Lines[currentline-2];
            //Console.Select(firstcharindex, currentlinetext.Length);
            Console.SelectionStart = firstcharindex;
            String errorText = Console.Text.Substring(firstcharindex);
            if (errorText.StartsWith("^ error"))
            {
                Console.DeselectAll();
                Form1 f = (Form1)this.MdiParent;
                f.edit.editor.SelectionStart = lineaMarcadaError;
                f.edit.editor.Focus();
            }
            else
            {
                Console.DeselectAll();
            }
        }
    }
}
